<?php
set_time_limit(0);
ini_set("display_errors", "On");
error_reporting(E_ALL | E_STRICT);
//http://newsletter.omnimkt.com/email/cron-log.php
$dbhost='127.0.0.1';
$dbuser='root';
$dbpwd ='song@491497047';
$dbName='email';

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}

$query=$mysqli->query("SELECT id,tagname FROM tag where flagid=0 limit 0,1 ");
$day=date("Y-m-d", strtotime("-1 day"));
if($query->num_rows>0){
    $getTag=$query->fetch_assoc();
    $thetag=$getTag['tagname'];
    $tagId=$getTag['id'];
    echo $thetag;
    echo "<br />";
    $sql="SELECT count(id) as count FROM analyse where day='".$day."' and  tag='".$thetag."' ";
    $queryPv=$mysqli->query($sql);
    $pvInfo=$queryPv->fetch_array();
    $sql="SELECT count(DISTINCT uid) as count FROM analyse where day='".$day."' and  tag='".$thetag."'  ";
    $queryUv=$mysqli->query($sql);
    $uvInfo=$queryUv->fetch_array();
 
    $sql="SELECT count(DISTINCT ip) as count FROM analyse where day='".$day."' and  tag='".$thetag."'  "; 
    $queryIp=$mysqli->query($sql);
    $ipInfo=$queryIp->fetch_array();
    
    $query=$mysqli->query("SELECT id FROM log_2 where day='".$day."' and tag='".$thetag."'  limit 0,1 ");
    if($query->num_rows>0){
        
    }else{
        $sql="insert into log_2(day,pv,uv,ip,tag) values('".$day."','".$pvInfo['count']."','".$uvInfo['count']."'
,'".$ipInfo['count']."','".$thetag."')";
        $mysqli->query($sql);
    }
    
    $mysqli->query("UPDATE `tag` SET `flagid` =1 where id='".$tagId."' ");
}
echo 1;